//
//  WrongQuestionSubmitController.m
//  Learn
//
//  Created by 迟建国 on 2024/4/7.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "WrongQuestionSubmitController.h"
#import "QuestionMessageTableViewCell.h"
#import "TestFinishViewController.h"

@interface WrongQuestionSubmitController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation WrongQuestionSubmitController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订正错题 回答问…";
    self.view.backgroundColor = rgba(245, 245, 245, 1);
    [self setUI];
    [self setNavUI];
    // Do any additional setup after loading the view.
}

- (void)setUI {
    
    self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(10,NavigationBarHeight + 10, SCREEN_W - 20, SCREEN_H - NavigationBarHeight - SafeAreaBottomHeight - 70) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    if (@available(iOS 13.0, *)) {
        [self.tableView setAutomaticallyAdjustsScrollIndicatorInsets:NO];
    } else {
        // Fallback on earlier versions
    }
    if (@available(iOS 15.0, *)) {
        self.tableView.sectionHeaderTopPadding = 0;
    } else {
        // Fallback on earlier versions
    }
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    self.tableView.backgroundColor=[UIColor whiteColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    self.tableView.layer.cornerRadius = 15;
    self.tableView.layer.masksToBounds = YES;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    [self.tableView registerNib:[UINib nibWithNibName:@"QuestionMessageTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"QuestionMessageTableViewCell"];
        
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_H - SafeAreaBottomHeight - 50, SCREEN_W, SafeAreaBottomHeight + 50)];
    bottomView.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:bottomView];
    
    UIButton *submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [submitBtn setTitle:@"交作业" forState:UIControlStateNormal];
    submitBtn.backgroundColor = rgba(41, 241, 156, 1);
    submitBtn.layer.cornerRadius = 22.5;
    submitBtn.layer.masksToBounds = YES;
    [submitBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    submitBtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:16];
    [submitBtn addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(10);
        make.top.equalTo(bottomView.mas_top).offset(3);
        make.right.equalTo(self.view.mas_right).offset(-10);
        make.height.offset(45);
    }];
}
- (void)setNavUI {
    UIView *nav = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, NavigationBarHeight)];
    nav.backgroundColor = rgba(245, 245, 245, 1);
    [self.view addSubview:nav];
//    self.nav = nav;
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [nav addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nav.mas_left).offset(5);
        make.bottom.equalTo(nav.mas_bottom);
        make.width.offset(50);
        make.height.offset(44);
    }];
    
    UILabel *titleL = [[UILabel alloc] init];
    titleL.text = @"订正错题 回答问…";
    titleL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:16];
    titleL.textColor = rgb(51, 51, 51);
    titleL.textAlignment = NSTextAlignmentCenter;
    [nav addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(nav.mas_bottom);
        make.centerX.equalTo(nav.mas_centerX);
        make.height.offset(44);
    }];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 390;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    QuestionMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QuestionMessageTableViewCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"QuestionMessageTableViewCell" owner:self options:nil] lastObject];
    }
    return cell;
}

- (void)submit {
    TestFinishViewController *vc = [[TestFinishViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
@end
